<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>同源策略 cors (Cross-Origin-Resource-Sharing)</title>
</head>

<body>
  <h2>请求回来的数据</h2>
  <p></p>
</body>

</html>
<!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script> -->
<script>
  // 本地端口号 :xxxxx
  // 接口端口号: 3000
  // 使用 axios.get 不存在跨域问题.
  // axios.get('http://localhost:3000/todoList')
  //   .then(response => {
  //     console.log(response)
  //   })
  //   .catch(error => {
  //     console.log(error)
  //   })
  let xmlhttp
  if (window.XMLHttpRequest) {
    xmlhttp = new XMLHttpRequest()
  } else {
    // 兼容 IE5,6
    xmlhttp = new ActiveXObject('microsoft.XMLHTTP')
  }

  if (xmlhttp) {

    xmlhttp.onreadystatechange = function () {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        // console.log(xmlhttp.responseText)
        document.getElementsByTagName('p')[0].innerText = xmlhttp.responseText
      }

    }
    // xmlhttp.open('GET', 'http://localhost:11111/json.data.json?v=' + Math.random(), true)
    xmlhttp.open('delete','http://localhost:11111/json.data.json/1', true)
    // xmlhttp.setRequestHeader('nidaye','caonidaye') // 修改 origin 请求头.
    xmlhttp.send()
  }


  // axios.get('same-origin.json')
  //   .then(response => {
  //     console.log(response)
  //   })

  // fetch('https://jsonplaceholder.typicode.com/todos/1')
  // .then(response => response.json())
  // .then(json => console.log(json))
</script>